import api from '../common/api';

export const listInitState = {
    loading: false,
    error: null,
    data: [],
    total: 0,
    offset: 0,
    limit: 10
};

export function getList(conditions, setVal, errorCb) {
    setVal({ ...listInitState, loading: true });

    const result = api({
        method: 'GET',
        url: 'controller/usermanageAction/getList.do',
        params: conditions
    })
    .then(data => setVal({
        ...listInitState,
        locading: false,
        ...data
    }))
    .catch(errorCb)
    return result;
}

export function deleteUser(id, cb, errorCb) {
    const result = api({
        method: 'GET',
        url: 'controller/usermanageAction/delete.do',
        params: { id }
    })
    .then(cb)
    .catch(errorCb);
    return result;
}

export function editor(id, contents, successCb, errorCb) {
    const result = api({
        method: 'GET',
        url: 'controller/usermanageAction/update.do',
        params: { id: id ? id : undefined, ...contents }
    })
    .then(successCb)
    .catch(errorCb);
    return result;
}